package com.tourism.controller;

import com.github.pagehelper.PageInfo;
import com.tourism.entity.AttractionCollect;
import com.tourism.entity.AttractionCollectQuery;
import com.tourism.exception.GlobalException;
import com.tourism.service.AttractionCollectService;
import com.tourism.util.common.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 景点收藏相关的控制器
 * @Author z
 * @Date 2021-03-01 20:40
 */
@Controller
@RequestMapping("/attractionCollect")
public class AttractionCollectController {


    @Autowired
    private AttractionCollectService attractionCollectService;

    /**
     * 根据景点收藏id查询景点收藏
     *
     * @param id
     * @return
     */
    @GetMapping("/getAttractionCollectById")
    @ResponseBody
    public AttractionCollect getAttractionCollectById(Long id) {
        return attractionCollectService.getAttractionCollectById(id);
    }

    /**
     * 根据景点收藏id删除景点收藏
     *
     * @param attractionId
     * @return
     */
    @GetMapping("/deleteCollectByAttractionId")
    @ResponseBody
    public Response deleteCollectByAttractionId(Long attractionId) {
        return Response.success(attractionCollectService.deleteCollectByAttractionId(attractionId));
    }

    /**
     * 根据景点判断是否被用户收藏过了
     *
     * @param attractionId 景点id
     * @return
     */
    @GetMapping("/isCollected")
    @ResponseBody
    public Response isCollected(Long attractionId) {
        return Response.success(attractionCollectService.isCollected(attractionId));
    }


    /**
     * 新增景点收藏
     *
     * @param attractionCollect
     * @return
     */
    @PostMapping("/addAttractionCollect")
    @ResponseBody
    public Response addAttractionCollect(@RequestBody AttractionCollect attractionCollect) throws GlobalException {
        return Response.success(attractionCollectService.addAttractionCollect(attractionCollect));

    }


    /**
     * 查询景点收藏列表
     *
     * @param attractionCollectQuery
     * @return
     */
    @PostMapping("/getAttractionCollectList")
    @ResponseBody
    public PageInfo<AttractionCollect> getattractionCollectList(@RequestBody AttractionCollectQuery attractionCollectQuery) {
        return attractionCollectService.getAttractionCollectList(attractionCollectQuery);
    }

}
